package com.waves.design.proxy;

/**
 * 代理查询类
 */
public class ProxySearcher implements Searcher{
    private RealSearcher searcher = new RealSearcher();
    private AccessValidator accessValidator;
    private Logger logger;


    @Override
    public String doSearch(String userId, String keyword) {
        if (validator(userId)) {
            String result = searcher.doSearch(userId, keyword);
            this.log(userId);
            return result;
        }
        return null;
    }


    private boolean validator(String userId) {
        accessValidator = new AccessValidator();
        return accessValidator.validate(userId);
    }

    private void log(String userId) {
        logger = new Logger();
        logger.log(userId);
    }


}
